package com.lonely.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.Select;
import com.lonely.common.core.domain.api.R;
import com.lonely.system.domain.dto.size.BatchAddSizeDto;
import com.lonely.system.domain.dto.size.SysSizePageQueryDto;
import com.lonely.system.domain.dto.size.SysSizeSubmitDto;
import com.lonely.system.domain.vo.system.size.SysSizePageQueryVo;
import com.lonely.system.service.ISysSizeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 黄志标
 * @date: 2025/6/17 17:07
 * @description: 尺码请求处理器
 */
@RestController
@RequestMapping("/systemManage/size")
@Api(tags = "系统管理/尺码管理")
public class SysSizeController {

    @Autowired
    private ISysSizeService sizeService;

    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
//    @SaCheckPermission("system:size:page")
    public R<Page<SysSizePageQueryVo>> page(@RequestBody SysSizePageQueryDto queryDto) {
        return R.data(this.sizeService.page(queryDto));
    }


    /**
     * 创建尺码
     *
     * @param batchAddSizeDto
     * @return
     */
    @PostMapping("/create")
    @ApiOperation(value = "创建尺码")
    @SaCheckPermission("system:size:create")
    public R<Boolean> create(@RequestBody @Validated BatchAddSizeDto batchAddSizeDto) {
        this.sizeService.create(batchAddSizeDto);
        return R.status(true);
    }


    /**
     * 编辑尺码
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation(value = "编辑尺码")
    @SaCheckPermission("system:size:edit")
    public R<Boolean> edit(@RequestBody @Validated SysSizeSubmitDto submitDto) {
        this.sizeService.edit(submitDto);
        return R.status(true);
    }

    /**
     * 启用尺码
     *
     * @param id
     * @return
     */
    @GetMapping("/enabled/{id}")
    @ApiOperation(value = "启用尺码")
    @SaCheckPermission("system:size:enabled")
    public R<Boolean> enabled(@PathVariable("id") Long id) {
        this.sizeService.enabled(id);
        return R.status(true);
    }

    /**
     * 禁用尺码
     *
     * @param id
     * @return
     */
    @GetMapping("/disable/{id}")
    @ApiOperation(value = "禁用尺码")
    @SaCheckPermission("system:size:disable")
    public R<Boolean> disable(@PathVariable("id") Long id) {
        this.sizeService.disable(id);
        return R.status(true);
    }

    /**
     * 获取尺码穿梭框选项值
     *
     * @return
     */
    @GetMapping("/getSizeTransferOptions")
    public R<List<Select>> getSizeTransferOptions() {
        return R.data(this.sizeService.getSizeTransferOptions());
    }

    /**
     * 获取商品尺码穿梭框选项值
     *
     * @return
     */
    @GetMapping("/getGoodsSizeTransferOptions")
    public R<List<Select>> getGoodsSizeTransferOptions() {
        return R.data(this.sizeService.getGoodsSizeTransferOptions());
    }
}
